Apple's standard image-compression dialog component allows you to customize the operation of the user dialog box in a number of ways. First, you can define a filter function. This function, which is a modal-dialog filter function, can process dialog box events before the component does. Your filter function can then perform custom processing that is appropriate to your application. Because the compression dialog box is a movable modal dialog box, you must provide a filter to process update events for your application windows.
Second, you can define a hook function. This function receives item hits before the standard image-compression dialog component does, and can therefore augment the basic dialog box. For example, your hook function can provide additional validation of the user's selections.
Finally, you can define a custom button in the dialog box. You can then use your hook function to detect when the user clicks this button. Your hook function can then extend the dialog box interface by displaying additional dialog boxes, for example.
You use the scExtendedProcsType request type with the SCSetInfo function to take advantage of these mechanisms for customizing the user dialog box. Listing 3 contains code that uses this function to define a custom button in the dialog box. Listing 4 contains this application's hook function.
Listing 3 Defining a custom button in the dialog box
SCExtendedProcs ep;
ep.filterProc = MyFilter; /* custom filter function */
ep.hookProc = MyHook; /* custom hook function */
ep.refcon = 0; /* reference constant for filter
and hook functions */
BlockMove("\pDefaults",ep.customName,32);
/* custom button name */
SCSetInfo(ci,scExtendedProcsType,&ep);
/* set new extended functions */
Listing 4 shows a hook function that returns the dialog box to its default settings whenever the user clicks the custom button. The standard dialog component calls this function each time the user selects an item in the dialog box. On entry, the hook function receives information about the current dialog box, a pointer to the appropriate standard image-compression dialog parameter block, and a reference constant that is supplied by your application.
This hook function first checks to see whether the user clicked the custom button. If so, the function changes the current compression settings.
Listing 4 A sample hook function
pascal short MyHook(DialogPtr theDialog,short itemHit,
void *params,long refcon)
{
SCSpatialSettings ss;
if (itemHit == scCustomItem) { /* check for custom item */
ss.codecType = 'jpeg'; /* create new settings */
ss.codec = anyCodec;
ss.depth = 32;
ss.spatialQuality = codecNormalQuality;
SCSetInfo(params, /* component connection */
scSpatialSettingsType, /* set spatial settings */
&ss); /* new spatial settings */
}
return (itemHit);
}
In your hook function, you may want to display additional user dialog boxes. Apple's standard image-compression dialog component provides two functions that help you position your dialog box on the screen. The SCPositionDialog function places a dialog box in a specified location; the SCPositionRect function positions a rectangle. By using these functions you can position your dialog boxes near the standard dialog box.
Listing 5 contains code that uses the SCPositionDialog function to place a Standard File Package dialog box onto the same screen as the standard image-compression dialog box.
Listing 5 Positioning related dialog boxes
Point where; /* positions dialog boxes */
ComponentInstance ci; /* component connection */
where.h = where.v = -2; /* center dialog box on the
best screen */
result = SCPositionDialog (ci, /* component connection */
-3999, /* resource number of dialog box */
&where); /* returns upper-left point */
SFPutFile (where, /* positions the dialog box */
"\pSave compressed picture as:",
"\pUntitled",
nil,
&outReply);